package com.asset.salesforce.service;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.springframework.stereotype.Service;


@Service
public class DateValidationUtil {
		
	public Boolean checkDateInFormDayMonthYear(final String date) {
	
		final String DATE_PATTERN = "(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/((19|20)\\d\\d)";
		Pattern pattern = Pattern.compile(DATE_PATTERN);
		Matcher matcher = pattern.matcher(date);
		if(matcher.matches()){
			 matcher.reset();
			 return true;
			 
		}else{
			return false;
		}
	}
	public Boolean checkDateInFormDayMonthYearDashes(final String date) {
		
		final String DATE_PATTERN = "(0?[1-9]|[12][0-9]|3[01])-(0?[1-9]|1[012])-((19|20)\\d\\d)";
		Pattern pattern = Pattern.compile(DATE_PATTERN);
		Matcher matcher = pattern.matcher(date);
		if(matcher.matches()){
			 matcher.reset();
			 return true;
			 
		}else{
			return false;
		}
	}
	public Date dateInFormDayMonthYear(final String date) {
		
		DateFormat format = new SimpleDateFormat("dd/MM/yyyy");
		Date date2;
		try {
			date2 = format.parse(date);
			return date2;
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
		
	}
public Date dateInFormYearMonthDay(final String date) {
		
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		Date date2;
		try {
			date2 = format.parse(date);
			return date2;
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
		
	}
public Date dateInFormDayMonthYearDashes(final String date) {
		
		DateFormat format = new SimpleDateFormat("dd-MM-yyyy");
		Date date2;
		try {
			date2 = format.parse(date);
			return date2;
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
		
	}
}
